package com.swyc.osschat.Jurisdiction.Controller;

import java.util.Arrays;
import java.util.Map;

import com.swyc.osschat.Common.Base.BaseController;
import com.swyc.osschat.Common.Result.Result;
import com.swyc.osschat.Common.Result.ResultFactory;
import com.swyc.osschat.Common.Util.Page.PageUtils;
import com.swyc.osschat.Common.Util.Page.ValidatorUtils;
import com.swyc.osschat.Jurisdiction.Entity.MenuEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("sys/sysmenu")
@Api(description = "权限：菜单管理")
public class SysMenuController extends BaseController<MenuEntity> {
    /**
     * 列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @RequiresPermissions("sys:sysmenu:list")
    @ApiOperation(value = "查询列表！")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = sysMenuService.queryPage(params);
        return ResultFactory.buildSuccessResult(page);
    }


    /**
     * 信息
     */
    @RequestMapping(value = "/info/{id}",method = RequestMethod.GET)
    @RequiresPermissions("sys:sysmenu:info")
    @ApiOperation(value = "根据id获取详细信息！")
    public Result info(Integer id){
        MenuEntity sysMenu = sysMenuService.getById(id);
        return ResultFactory.buildSuccessResult(sysMenu);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @RequiresPermissions("sys:sysmenu:save")
    @ApiOperation(value = "新增数据！")
    public Result save(@RequestBody MenuEntity sysMenu){
        boolean flag = sysMenuService.save(sysMenu);
        if (flag){
            return ResultFactory.buildSuccessResult("Success");
        }else {
            return ResultFactory.buildFailResult("Fail");
        }
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @RequiresPermissions("sys:sysmenu:update")
    @ApiOperation(value = "获取页面类容修改数据！")
    public Result update(@RequestBody MenuEntity sysMenu){
        ValidatorUtils.validateEntity(sysMenu);
        boolean flag = sysMenuService.updateById(sysMenu);
        if (flag){
            return ResultFactory.buildSuccessResult("Success");
        }else {
            return ResultFactory.buildFailResult("Fail");
        }
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    @RequiresPermissions("sys:sysmenu:delete")
    @ApiOperation(value = "根据id删除数据！")
    public Result delete(@RequestBody Integer[] ids){
        boolean flag = sysMenuService.removeByIds(Arrays.asList(ids));
        if (flag){
            return ResultFactory.buildSuccessResult("Success");
        }else {
            return ResultFactory.buildFailResult("Fail");
        }
    }

}
